﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Holoville.HOTween;

public partial class MainScene : Scene
{
	bool isClicked = false;

	#region Left Area

	public void OnClick_Friend() // 친구
	{
		LoadLevelWithDelay("Friend");
//		ToastUtility.UnavailableToast();
	}

    public void OnClick_Achievement()   { LoadLevelWithDelay("Achievement"); } // 업적
	public void OnClick_Shop()			{ // 상점
		ToastUtility.UnavailableToast(); 
//		LoadLevelWithDelay("Store");
	}

	public void OnClick_Quest() // 퀘스트
	{
		LoadLevelWithDelay("Quest");
//		ToastUtility.UnavailableToast();
	}
	#endregion
	
	
	#region Right Area
	public void OnClick_Boss()		{ LoadLevelWithDelay("BossList"); } // 보스전
	public void OnClick_World()		{ LoadLevelWithDelay("World_GStar"); } // 월드
	public void OnClick_Challenge() { ToastUtility.UnavailableToast(); } // 일일도전

	public void OnClick_Dungeon() // 던전
	{
		ToastUtility.UnavailableToast();
		return;
		
        //TODO:TEMP-BOSS WARNING
        UserData.Instance.raidBossId = 10002;
        UserData.Instance.researchResultData = UserData.Instance.researchResultData ?? new ResearchResultModel();
        UserData.Instance.researchResultData.discoverBossLv = 30;
        LoadLevelWithDelay("BossWarning");
	}
	#endregion


	#region Top Right Area
	public void OnClick_Notice()	{ ToastUtility.UnavailableToast(); } // 공지
	public void OnClick_Mailbox()	{ LoadLevelWithDelay("Message", 0.0f); } // 우편함

	public void OnClick_Option() // 옵션
	{
		/*
		ToastUtility.UnavailableToast();

        //TODO:Temp-BGM MUTE
        AudioSource bgm = GameObject.Find("BGMController").GetComponent<AudioSource>();
        bgm.mute = !bgm.mute;
		*/

		Popup_TwoButton pt = PopupManager.PushPopup(PopupKind.TwoButton) as Popup_TwoButton;
		pt.SetPopupWithTitleAndBody(Localization.Get("uiCommonTextwarning"), Localization.Get("GstarGameReStart"));
		pt.SetPopupWithYesNoString(Localization.Get("uiCommonTextCheck"), Localization.Get("uiCommonTextCancel"));
		pt.SetEventOK(gameObject, "ResetGame");
	}
	#endregion
	
	#region Center Area
	public void OnClick_Arena()			{ ToastUtility.UnavailableToast(); } // 투기장
	public void OnClick_Alliance() // 연합
	{
		ToastUtility.UnavailableToast();
		//LoadLevelWithDelayAndCameraAnimator("League", "Camera Path_League");
	} 
	public void OnClick_RVR()			{ ToastUtility.UnavailableToast(); } // RVR
	public void OnClick_Factory()		{ ToastUtility.UnavailableToast(); } // 제작소
	public void OnClick_ManagingGuild() { LoadLevelWithDelayAndCameraAnimator("Character_Info", "Camera Path_GuildCare"); } // 길드원 관리
	public void OnClick_WaitingRoom()	{ LoadLevelWithDelayAndCameraAnimator("Recruit", "Camera Path_GuildHall"); } // 길드원 대기소

	public void OnClick_Invasion() // 침략
	{
		ToastUtility.UnavailableToast();
		// OpenPopupQuickPVP();
	}
	#endregion

	void LoadLevelWithDelay(string sceneName, float delay = POST_CLICK_DELAY)
	{
		if (isClicked) return;
		isClicked = true;

		StartCoroutine(DelayedLoadLevel(sceneName, delay));
	}

	void LoadLevelWithDelayAndCameraAnimator(string sceneName, string cameraAnimatorName, float delay = POST_CLICK_DELAY)
	{
		if (isClicked) return;
		isClicked = true;
		
		if (GameObject.Find(cameraAnimatorName))
		{
			HidePanel();
			GameObject.Find(cameraAnimatorName).GetComponent<CameraPathBezierAnimator>().Play();
		}
		
		StartCoroutine(DelayedLoadLevel(sceneName, delay));
	}

	IEnumerator DelayedLoadLevel(string sceneName, float delay)
	{
		yield return new WaitForSeconds(delay);
		SceneController.LoadLevel(sceneName, delay);
	}

}